// 表单
var SysFormClass = function() {};
              
SysFormClass.prototype = {
    /*
     * toolbar button
     */
    hd: [
        {
            label: 'blod', 
            action: 'SysForm.addBold();', 
            alt: 'Bold', 
            className: ''
        },
        {
            label: 'table', 
            action: '#TB_inline?height=430&width=350&inlineId=SysFormTableDiv', 
            alt: 'Table', 
            className: 'thickbox'
        },
        {
            label: 'text', 
            action: '#TB_inline?height=430&width=350&inlineId=SysFormTextDiv', 
            alt: 'Text', 
            className: 'thickbox'
        }
     ], 
    ci: "", // div contain id
    chs: "", // div header id
    cbs: "", // iframe editor id
    oc: Object, // contain object
    oh: Object, // div header 
    ob: Object, // iframe editor
                
    h: 0, // 高
    w: 0, // 宽
                
    init: function(tbDivId, formConfig) {
        this.ci = tbDivId;
        this.oc = $("#" + tbDivId);
        this.oc.addClass("sysform");
        
        this.chs = tbDivId + "_header";
        this.cbs = tbDivId + "_body";
        $("#" + tbDivId).append("<div class='sysform_hd' id='" + this.chs + "'></div>");
        $("#" + tbDivId).append("<iframe class='sysform_bd' id='" + this.cbs + "' border='0' marginWidth='0' marginHeight='0'></iframe>");
        this.oh = $("#" + this.chs);
        this.ob = $("#" + this.cbs);
        
        this.h = formConfig.height;
        this.w = formConfig.width;
        
        // 设置可编辑状态
        editor = document.getElementById(this.cbs).contentWindow;
        editor.document.designMode = "On";
        editor.document.contentEditable = true;
        editor.document.open();
        var defaultHtml = "";
        defaultHtml += "<html><head>";
        defaultHtml += "<style>";
        defaultHtml += "body, table{font-size:14px;font-family:georgia, times new roman, serif;};";
        defaultHtml += "</style>";
        defaultHtml += "</head><body style='padding:5px;'></body></html>";
        editor.document.writeln(defaultHtml);
        editor.document.close();
                
        // 设置工具条
        this.setToolbar();
        
        // 设置宽度和高度
        this.setForm();
        
        o_xsys_form_iframe_id = this.cbs;
    },
    setForm: function() {
        // 设置容器宽度和高度
        this.oc.css("height", this.h + "px");
        this.oc.css("width", this.w + "px");
                    
        // 设置内容高度
        var hh = this.oh.attr("scrollHeight");
        this.ob.css("width", (this.w - 2) + "px");
        this.ob.css("height", (this.h - hh) + "px");
    },
    // 设置大小
    setRect: function(w, h) {
        this.w = w;
        this.h = h;
    },
    // 添加工具栏按钮
    setToolbar: function() {
        var htmlStr = "";
        for(i = 0; i < this.hd.length; i++) {
            fhd = this.hd[i];
            if(fhd.className == "thickbox") {
                htmlStr += "<a href='" + fhd.action 
                    + "' class='thickbox'>" 
                    + fhd.label + "</a>&nbsp;";
            } else {
                htmlStr += "<a href='javascript:' onclick='" 
                    + fhd.action + "'>" 
                    + fhd.label + "</a>&nbsp;";
            }
        }
        this.oh.append(htmlStr);
    }
};
